IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'BillDetail_InProdDetail') and OBJECTPROPERTY(ID, N'IsUserTable') = 1) BEGIN

   CREATE TABLE [BillDetail_InProdDetail] (
   	[Id] INT IDENTITY (1, 1) NOT NULL ,
   	[BillDetailId]	INT NOT NULL,
   	[InProdDetailId]		INT NOT NULL,
   	[Amount]		INT NOT NULL
   
      -- Create non-clustered primary key
   	CONSTRAINT [rpk_BillDetail_InProdDetail] PRIMARY KEY NONCLUSTERED 
   	(
   		[Id]
   	)  ON [PRIMARY] ,
   ) ON [PRIMARY]
   
   ALTER TABLE dbo.[BillDetail_InProdDetail]
	ADD CONSTRAINT rfk_BillDetail_InProdDetail_BillDetail_FKID FOREIGN KEY
		( [BillDetailId] ) 
	REFERENCES dbo.BillDetail
		( [Id] )
	ON DELETE CASCADE

	ALTER TABLE dbo.[BillDetail_InProdDetail]
	ADD CONSTRAINT rfk_BillDetail_InProdDetail_InProdDetail_FKID FOREIGN KEY
		( [InProdDetailId] ) 
	REFERENCES dbo.InOutProdDetail
		( [Id] )
	ON DELETE CASCADE

END